package com.yun.baymax.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.yun.baymax.R;
import com.yun.baymax.activity.FinancialActivity;
import com.yun.baymax.activity.NoteActivity;
import com.yun.baymax.activity.PasswordKeepAct;
import com.yun.baymax.adapter.AssistantAdapter;
import com.yun.baymax.bean.adapter.Assistant;
import com.yun.lib.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class AssistantFragment extends BaseFragment {
    List<Assistant> datas = new ArrayList<>();
    private Context mContext;

    @Override
    protected int setLayoutResourceId() {
        mContext = getContext();
        return R.layout.fragment_assistant;
    }

    @Override
    protected void initViews(Bundle savedInstanceState, View view, LayoutInflater inflater) {
        generateData();
        RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
        mRecyclerView.setLayoutManager(gridLayoutManager);
        AssistantAdapter assistantAdapter = new AssistantAdapter(mContext, datas);
        mRecyclerView.setAdapter(assistantAdapter);
    }

    protected void generateData() {
        datas.clear();
        Assistant passwordAct = new Assistant(R.drawable.password_bg, "密码管理", PasswordKeepAct.class);
        passwordAct.setFragmentManager(getChildFragmentManager());
        datas.add(new Assistant(R.drawable.financial_bg, "财务管理", FinancialActivity.class));
        datas.add(passwordAct);
        datas.add(new Assistant(R.drawable.note_bg, "记事本", NoteActivity.class));
    }
}
